﻿//        Another Demo from Andy L. & MissedMemo.com
// Borrow whatever code seems useful - just don't try to hold
// me responsible for any ill effects. My demos sometimes use
// licensed images which CANNOT legally be copied and reused.

using System;
using System.Linq;
using System.Xml.Linq;


namespace MissedMemo.MeatAndCheeseDisc.UIHelperClasses
{
    public static class TimeLimitLookup
    {
        private readonly static string strTimeLimitFileName = "TimeLimits.xml";


        public static TimeSpan GetLimit( string strLimit )
        {
            XElement data = XElement.Load( strTimeLimitFileName );

            var query =
                from limit in data.Descendants( "TimeLimit" )
                where (String)limit.Attribute( "DisplayName" ) == strLimit
                select limit.Descendants( "Minutes" ).First().Value;

            double numMinutes = 0;

            if( query.Count() > 0 )
                Double.TryParse( query.ElementAt( 0 ), out numMinutes );

            return TimeSpan.FromMinutes( numMinutes );
        }
    }
}
